{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "import numpy as np\n",
    "import random"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 78,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "['0', '1', '2', '3', '4', '5', '6', '7', '8', '9']\n",
      "10\n"
     ]
    }
   ],
   "source": [
    "char_set = [str(i) for i in range(10)]\n",
    "# char_set = np.array(char_set)\n",
    "print(char_set)\n",
    "print(len(char_set))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 80,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'4165'"
      ]
     },
     "execution_count": 80,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "def get_captcha():\n",
    "    return ''.join(random.choices(char_set,k=4))\n",
    "\n",
    "get_captcha()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 81,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['3518',\n",
       " '1658',\n",
       " '8888',\n",
       " '2449',\n",
       " '1521',\n",
       " '5733',\n",
       " '8781',\n",
       " '1649',\n",
       " '4118',\n",
       " '6826']"
      ]
     },
     "execution_count": 81,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "cc = [get_captcha() for i in range(10)] \n",
    "cc"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 82,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "['3518' '1658' '8888' '2449' '1521' '5733' '8781' '1649' '4118' '6826']\n",
      "(10,)\n"
     ]
    }
   ],
   "source": [
    "aa = np.array(cc)\n",
    "print(aa)\n",
    "print(aa.shape)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 83,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([['3518'],\n",
       "       ['1658'],\n",
       "       ['8888'],\n",
       "       ['2449'],\n",
       "       ['1521'],\n",
       "       ['5733'],\n",
       "       ['8781'],\n",
       "       ['1649'],\n",
       "       ['4118'],\n",
       "       ['6826']], dtype='<U4')"
      ]
     },
     "execution_count": 83,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "bb = aa.reshape(-1,1)\n",
    "bb"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 86,
   "metadata": {},
   "outputs": [],
   "source": [
    "def get_index(x):\n",
    "    return char_set.index(x)\n",
    "def get_single(a):\n",
    "    return [get_index(a[0][0]),get_index(a[0][1]),get_index(a[0][2]),get_index(a[0][3])]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 87,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[3, 5, 1, 8],\n",
       "       [1, 6, 5, 8],\n",
       "       [8, 8, 8, 8],\n",
       "       [2, 4, 4, 9],\n",
       "       [1, 5, 2, 1],\n",
       "       [5, 7, 3, 3],\n",
       "       [8, 7, 8, 1],\n",
       "       [1, 6, 4, 9],\n",
       "       [4, 1, 1, 8],\n",
       "       [6, 8, 2, 6]])"
      ]
     },
     "execution_count": 87,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "ee = np.apply_along_axis(get_single,1,bb)\n",
    "ee"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 88,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[3],\n",
       "       [1],\n",
       "       [8],\n",
       "       [2],\n",
       "       [1],\n",
       "       [5],\n",
       "       [8],\n",
       "       [1],\n",
       "       [4],\n",
       "       [6]])"
      ]
     },
     "execution_count": 88,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "ee[:,0].reshape(-1,1)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.6"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
